package org.geektimes.projects.user.validator.bean.validation;

import org.geektimes.projects.user.domain.User;

import javax.validation.ConstraintValidator;
import javax.validation.ConstraintValidatorContext;
import java.util.regex.Pattern;

public class PhoneNumberValidAnnotationValidator implements ConstraintValidator<PhoneNumberValid, String> {

    public void initialize(PhoneNumberValid annotation) {
    }

    @Override
    public boolean isValid(String phone, ConstraintValidatorContext context) {
        Pattern pattern = Pattern.compile("^[1]\\d{10}$");
        return pattern.matcher(phone).matches();
    }
}
